from weed_shop.core.models.dto.cart import CartDTO, CartLineDTO
from weed_shop.infrastructure.database.models import Cart, CartProduct


def convert_db_model_to_cartlines_dto(line: CartProduct) -> CartLineDTO:
    return CartLineDTO(product_id=line.product_id, quantity=line.quantity, final_unit_price=line.final_unit_price)


def convert_db_model_to_cart_dto(cart: Cart) -> CartDTO:
    cart_lines = [convert_db_model_to_cartlines_dto(line) for line in cart.lines]

    return CartDTO(id=cart.id, lines=cart_lines, user_id=cart.user_id)
